package com.example.yls.demoa;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button btnOpen;
    private Button btnInsert;
    private Button btnSearch;

    private SQLiteOpenHelper sqLiteOpenHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        btnOpen = findViewById(R.id.btn_sql);
        btnOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 sqLiteOpenHelper = new StudbOpenHelper(MainActivity.this,
                        "stu.db",null,3);

            }
        });
        btnInsert = findViewById(R.id.btn_insert);
        btnInsert.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLiteDatabase sqLiteDatabase = sqLiteOpenHelper.getWritableDatabase();
                sqLiteOpenHelper.getReadableDatabase();
                ContentValues values = new ContentValues();
                values.put("stuno",17001);
                values.put("name","素素");
                values.put("age",19);
                sqLiteDatabase.insert("student",null,values);
            }
        });
 /*       btnSearch = findViewById(R.id.btn_search);
        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sqLiteOpenHelper = new StudbOpenHelper(MainActivity.this,
                        "stu.db",null,1);

            }
        });*/



    }
}
